package cn.tedu.charging.commen.utils;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
    private static ObjectMapper objectMapper = new ObjectMapper();

    public static String toJson(Object object){
        try {
            String string = objectMapper.writeValueAsString(object);
            return string;
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    public static <T> T toObject(String json,Class<T> clazz){
        try {
            T t = objectMapper.readValue(json, clazz);
            return t;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
